package com.ssy.lingxi.pay.controller.mobile;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.pay.model.assetAccount.*;
import com.ssy.lingxi.pay.model.dto.UrlLinkDTO;
import com.ssy.lingxi.pay.service.IWeChatPayService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @menu 微信支付相关接口
 * @author lqa
 * @version 2.0.0
 * @date 2022/3/17
 */
@RestController
@RequestMapping("/pay/weChat/mobile")
public class MobileWeChatFeignController {

    @Resource
    private IWeChatPayService weChatPayService;

    /**
     * 获取微信AccessToken
     *
     * @param accessTokenRequest 请求参数
     * @return  操作结果
     */
    @GetMapping("/getAccessToken")
    public Wrapper<AccessToken> getAccessToken(AccessTokenRequest accessTokenRequest) {
        AccessToken accessToken = weChatPayService.getWeChatAccessToken(accessTokenRequest);
        return Wrapper.success(accessToken);
    }

    /**
     * 获取微信JsApiTicket
     *
     * @param accessTokenRequest 请求参数
     * @return 操作结果
     */
    @GetMapping("/getJsApiTicket")
    public Wrapper<JsApiTicket> getJsApiTicket(AccessTokenRequest accessTokenRequest) {
        JsApiTicket jsApiTicket = weChatPayService.getJsApiTicket(accessTokenRequest);
        return Wrapper.success(jsApiTicket);
    }

    /**
     * 获取JS-SDK签名
     *
     * @param jsApiRequest 请求参数
     * @return 操作结果
     */
    @GetMapping("/getSignature")
    public Wrapper<JsApiResult> getJsApiResult(JsApiRequest jsApiRequest) {
        JsApiResult jsApiResult = weChatPayService.getJsApiResult(jsApiRequest);
        return Wrapper.success(jsApiResult);
    }


    /**
     * 先获取微信AccessToken,根据AccessToken获取url_link
     *
     * @return url_link
     */
    @PostMapping("/getUrlLink")
    public Wrapper<String> getUrlLink(@RequestBody UrlLinkDTO urlLinkDTO) {
        return Wrapper.success(weChatPayService.getUrlLink(urlLinkDTO));
    }

}
